package com.tang.algorithm.swordFingerOffer;

import java.util.ArrayList;

/**
 * @author tlm
 * @version 1.0
 * @date 2020/4/26 10:01
 * 打印从1到最大的n位数
 * 链接：https://leetcode-cn.com/problems/da-yin-cong-1dao-zui-da-de-nwei-shu-lcof
 */
public class PrintNDigitsFrom1ToMaximum {
    public static void main(String[] args) {
        int a[] = printNumbers2(3);
        for (int i = 0; i < a.length; i++) {
            System.out.println(a[i]);
        }

    }

    public static int[] printNumbers(int n) {
        ArrayList<Integer> list = new ArrayList<>();
        int num = 0,wei;
        while (true) {
            num++;
            int x = num;
            wei = 0;
            while (x > 0) {
                x = x / 10;
                wei++;
            }
            if (wei > n) break;
            list.add(num);
        }
        int a[] = new int[list.size()];
        int index = 0;
        for (Integer i : list) {
            a[index++] = i;

        }
        return a;
    }
    //解法2
    public static int[] printNumbers2(int n) {
        int x = (int)Math.pow(10,n);
        System.out.println(x);
        int y = x-1;
        int a[] = new int [y];
        for(int i=0;i<y;i++){
            a[i]=i+1;
        }
        return a;
    }
}
